package com.xiaohu.myspace.action;

import java.util.List;

import com.xiaohu.myspace.buiness.buinessinterface.OptionInfoInterface;
import com.xiaohu.myspace.database.entity.OptionInfo;

public class OptionInfoAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	
	private OptionInfo optionInfo;
	private String returnData;
	private OptionInfoInterface optionInfoInterface;
	public OptionInfo getOptionInfo() {
		return optionInfo;
	}
	public void setOptionInfo(OptionInfo optionInfo) {
		this.optionInfo = optionInfo;
	}
	public OptionInfoInterface getOptionInfoInterface() {
		return optionInfoInterface;
	}
	public void setOptionInfoInterface(OptionInfoInterface optionInfoInterface) {
		this.optionInfoInterface = optionInfoInterface;
	}
	
	
	public String getReturnData() {
		return returnData;
	}
	public void setReturnData(String returnData) {
		this.returnData = returnData;
	}
	public String addOptionInfo(){
		if (null == optionInfo) {
			return ERROR;
		}
		boolean flag=optionInfoInterface.addOptionInfo(optionInfo);
		if (flag) {
			returnData = initReturnData(SUCCESSCODE, optionInfo);
			System.out.println(returnData);
			return SUCCESS;
		}
		
		return ERROR;
	}
	
	public String deleteOptionInfo(){
		if (null == optionInfo) {
			return ERROR;
		}
		boolean flag=optionInfoInterface.deleteOptionInfo(optionInfo);
		if (flag) {
			returnData = initReturnData(SUCCESSCODE, optionInfo);
			System.out.println(returnData);
			return SUCCESS;
		}
		
		return ERROR;
	}
	public String updateOptionInfo(){
		if (null == optionInfo) {
			return ERROR;
		}
		boolean flag=optionInfoInterface.updateOptionInfo(optionInfo);
		if (flag) {
			returnData = initReturnData(SUCCESSCODE, optionInfo);
			System.out.println(returnData);
			return SUCCESS;
		}
		
		return ERROR;
	}
	public String selectOptionInfo(){
		if (null == optionInfo) {
			return ERROR;
		}
		List<OptionInfo> optionInfos=optionInfoInterface.selectOptionInfoWithOptionCode(optionInfo.getOptionCode());
		if ((null!=optionInfos)&&(optionInfos.size()>0)) {
			returnData = initReturnData(SUCCESSCODE, optionInfos);
			System.out.println(returnData);
			return SUCCESS;
		}
		
		return ERROR;
	}

}
